var t = getApp();

Page({
    data: {
        language: "",
        show: !1,
        count: 1,
        color: [ "黑色", "白色" ],
        price_list: [ 20, 20, 45 ],
        list: [],
        current_options: {},
        total: 0,
        title: "",
        has_many_specs: [],
        has_many_options: [],
        thumb: "",
        id: 0,
        goods: [],
        give_active_value: "",
        shop_package_id: "",
        specs: ""
    },
    close: function() {
        this.setData({
            show: !1
        });
    },
    choose: function(t) {
        var a = this;
        console.log(t.currentTarget.dataset);
        var o = t.currentTarget.dataset, s = o.i, i = o.item, n = o.c_item, e = "";
        this.data.list.forEach(function(t) {
            t.id == a.data.id && (t.has_many_specs.forEach(function(a, o) {
                if (a.id == i.id) {
                    a.index = s;
                    var c = t.current_options.specs.split("_");
                    c[o] = n.id + "", e = c.join("_");
                }
            }), t.has_many_options.forEach(function(o) {
                o.specs == e && (t.current_options = o, a.data.current_options = o);
            }));
        }), this.data.has_many_specs.forEach(function(t) {
            t.id == i.id && (t.index = s);
        }), this.setData({
            list: this.data.list,
            has_many_specs: this.data.has_many_specs
        });
        var c = this.data.has_many_options.filter(function(t) {
            return t.specs == e;
        });
        this.data.goods.forEach(function(t) {
            t.goods_id == a.data.id && (t.option_id = c[0].id);
        }), this.setData({
            goods: this.data.goods,
            current_options: this.data.current_options
        }), this.total_price();
    },
    minus: function() {
        this.data.count > 1 && (this.data.count -= 1, this.data.goods.forEach(function(t) {
            t.total -= 1;
        }), this.setData({
            count: this.data.count,
            goods: this.data.goods
        }), this.total_price());
    },
    specification: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            show: !0,
            title: a.title,
            has_many_specs: a.has_many_specs,
            thumb: a.thumb,
            has_many_options: a.has_many_options,
            current_options: a.current_options,
            id: a.id
        });
    },
    pay: function() {
        var t = [];
        this.data.goods.forEach(function(a) {
            t.push(a.goods_id);
        }), t = t.join(), wx.navigateTo({
            url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=sign_buy&package_id=".concat(this.data.shop_package_id, "&goodsId=").concat(t, "&goods=").concat(JSON.stringify(this.data.goods))
        });
    },
    plus: function() {
        this.data.count += 1, this.data.goods.forEach(function(t) {
            t.total += 1;
        }), this.setData({
            count: this.data.count,
            goods: this.data.goods
        }), this.total_price();
    },
    onLoad: function(t) {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        }), this.getData();
    },
    onReady: function() {},
    total_price: function() {
        var t = (this.data.list.filter(function(t) {
            return 0 == t.has_option;
        }).reduce(function(t, a) {
            return t + Number(a.price);
        }, 0) + this.data.list.filter(function(t) {
            return 1 == t.has_option;
        }).reduce(function(t, a) {
            return t + Number(a.current_options.product_price);
        }, 0)) * this.data.count;
        this.setData({
            total: t
        });
    },
    getData: function() {
        var a = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.sign-buy.frontend.package.index.home"),
            success: function(o) {
                var s = o.data, i = s.result, n = s.msg, e = s.data, c = e.goods_list, d = e.give_active_value, r = e.shop_package_id;
                if (0 == i) return t.tips(n);
                console.log(r), a.setData({
                    list: c,
                    give_active_value: d,
                    shop_package_id: r
                }), a.data.list.forEach(function(t) {
                    t.has_many_specs.forEach(function(t) {
                        t.index = 0;
                    }), t.current_options = t.has_many_options[0], 1 == t.has_option && a.data.goods.push({
                        goods_id: t.id,
                        total: 1,
                        option_id: t.has_many_specs[0].id
                    }), 0 == t.has_option && a.data.goods.push({
                        goods_id: t.id,
                        total: 1,
                        option_id: 0
                    });
                }), a.setData({
                    list: a.data.list,
                    goods: a.data.goods
                }), a.total_price();
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});